<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增sys_schedul_zhi')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-zhi-add">
            <h4 class="form-header h4">sys_schedul_zhi信息</h4>
            <div class="form-group">    
                <label class="col-sm-3 control-label">值班名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排班编号：</label>
                <div class="col-sm-8">
<!--                    <input name="paiName" class="form-control" type="text">-->
                    <select name="paiName"  class="form-control">
                        <option value=""></option>
                        <option th:each="item,info:${relates}" th:object="${item}" th:value="*{paiId}">
                            <span th:text="*{paiId}"></span>
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属部门：</label>
                <div class="col-sm-8">
                    <input name="deptId" type="hidden" id="treeId"/>
                    <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
                </div>
            </div>
           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">排班id 联查排班：</label>
                <div class="col-sm-8">
                    <input name="paiId" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">创建人：</label>
                <div class="col-sm-8">
<!--                    <input name="createName" class="form-control" type="text">-->
                    <input name="createName" class="form-control" th:value="${user.userId}" type="hidden">
                    <span th:text="${user.userName}"></span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">值班人：</label>
                <div class="col-sm-8">
<!--                    <input name="workName" class="form-control" type="text">-->
                    <select name="workName"  class="form-control">
                        <option value=""></option>
                        <option th:each="item,info:${users}" th:object="${item}" th:value="*{userId}">
                            <span th:text="*{userName}"></span>
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">值班时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
<!--                        <input name="workTime" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
                        <select name="workTime"  class="form-control times" onblur="check()">
                            <option value=""></option>
                            <option th:each="item,info:${relates}" th:object="${item}" th:value="*{beginTime}">
                                <span th:text="*{beginTime}"></span>
                            </option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="text" class="form-control"></textarea>
                </div>
            </div>
          <!--  <h4 class="form-header h4">schedul_pai_relate信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/zhi"
        $("#form-zhi-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-zhi-add').serialize());
            }
        }
        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            console.log(deptId)
            $.modal.openOptions(options);
        }
        //判断方法,反会时间数组,如果有一样的,就不让选
        function check(){
            console.log($('.times').val())

        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
        $("input[name='workTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'beginTime',
                    align: 'center',
                    title: '开始时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysSchedulPaiRelateList[%s].beginTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'endTime',
                    align: 'center',
                    title: '结束时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysSchedulPaiRelateList[%s].endTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'zhiId',
                    align: 'center',
                    title: '值班人id',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysSchedulPaiRelateList[%s].zhiId' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                beginTime: "",
                endTime: "",
                zhiId: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>